<template>
  <div>
    <Chart :cdata="cdata" />
  </div>
</template>

<script>
import Chart from './chart.vue';
export default {
  data () {
    return {
      cdata: {
        xData: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        yData: [150, 230, 224, 218, 135, 147, 260],
      },
      // websocket 获得的数据
      storeDatas: null
    }
  },
  components: {
    Chart,
  },
  mounted () {
  // 注册监听事件
  window.addEventListener('onmessageWS', this.getsocketData)
  // 定义数据
  let sandData = {"msgtype":"startsubscribe","p1":1000,"ps":["Sim1#tag1"]}
  // 发送数据
  this.$sendMg(sandData)

  },
  methods: {
    // 接收消息
    getsocketData(e){
      const data = e && e.detail.data
      this.storeDatas = JSON.parse(data)

      console.log(this.storeDatas)
      // return data  
    }
  },
  destroyed() {
  // 在需要的时候卸载监听事件，比如离开页面
  window.removeEventListener('onmessageWS', this.getsocketData)
  }
}
</script>

<style lang="scss" scoped>
</style>